package com.dj.ms.support.plus;

import com.dj.ms.support.ConfigProcessor;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;


/**
 * <br>
 * <p>
 *     代码生成器配置信息
 * </p>
 *
 * <br>
 * @author ZJG
 * @version 1.0
 * @date 2021/9/29 上午10:19
 */
@Setter
@Getter
@Configuration
@ConfigurationProperties(prefix = "orm.code.generate")
public class GeneratorConfig {

    /**
     * 作者
     */
    private String author = "ZJG";
    /**
     * 目录(项目绝对路径）
     */
    private String adsDirectory = System.getProperty("os.name").toLowerCase().contains("windows") ? "C://" : "/tmp";
    /**
     * 包名（全名称）
     */
    private String parentPkg = "com.zjg";
    /**
     * dto service 子包
     */
    private String daoSerPkg;

    /**
     * 表前缀
     */
    private String[] tbPrefix;

    /**
     * 表匹配（正则表达式）
     */
    private String[] tbMatch;

    /**
     * 表后缀
     */
    private String[] tbSuffix;

    private Class<?> superEntityCls;
    private Class<?> superControllerCls;
    private Class<?> superServiceCls;
    private Class<?> superServiceImplCls;

    public static class Processor implements ConfigProcessor<GeneratorConfig> {

        private final GeneratorConfig generatorConfig;
        public Processor() {
            this.generatorConfig = new GeneratorConfig();
        }

        public Processor author(String author){
            this.generatorConfig.author = author;
            return this;
        }

        public Processor adsDirectory(String adsDirectory){
            this.generatorConfig.adsDirectory = adsDirectory;
            return this;
        }

        public Processor parentPkg(String parentPkg){
            this.generatorConfig.parentPkg = parentPkg;
            return this;
        }


        public Processor daoSerPkg(String daoSerPkg){
            this.generatorConfig.daoSerPkg = daoSerPkg;
            return this;
        }

        public Processor tbPrefix(String... tbPrefix){
            this.generatorConfig.tbPrefix = tbPrefix;
            return this;
        }

        public Processor tbSuffix(String... tbSuffix){
            this.generatorConfig.tbSuffix = tbSuffix;
            return this;
        }

        public Processor tbMatch(String... tbMatch){
            this.generatorConfig.tbMatch = tbMatch;
            return this;
        }

        public Processor superEntityCls(Class<?> superEntityCls){
            this.generatorConfig.superEntityCls = superEntityCls;
            return this;
        }

        public Processor superControllerCls(Class<?> superControllerCls){
            this.generatorConfig.superControllerCls = superControllerCls;
            return this;
        }

        public Processor superServiceCls(Class<?> superServiceCls){
            this.generatorConfig.superServiceCls = superServiceCls;
            return this;
        }

        public Processor superServiceImplCls(Class<?> superServiceImplCls){
            this.generatorConfig.superServiceImplCls = superServiceImplCls;
            return this;
        }

        @Override
        public GeneratorConfig process() {
            return this.generatorConfig;
        }
    }


}
